package com.sicheng.lc.周赛.分类.位运算;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/6/27 10:16
 */
public class 操作后的最大异或和 {
    //https://leetcode.cn/problems/maximum-xor-after-operations/
    public int maximumXOR(int[] nums) {
        int[] bits = new int[28];
        for (int num : nums) {
            for (int i = 0; num >> i > 0 && i < bits.length; i++) {
                if ((num >> i & 1) == 1)
                    bits[i]++;
            }
        }
        int res = 0;
        for (int i = 0; i < bits.length; i++) {
            if ((bits[i] & 1) == 0 && bits[i] > 0) {
                bits[i]++;
            }
            res += (bits[i] & 1) == 0 ? 0 : 1 << i;
        }
        return res;
    }

    public static void main(String[] args) {
        操作后的最大异或和 s = new 操作后的最大异或和();
        int[] nums = {1, 2, 3, 9, 2};
        System.out.println(s.maximumXOR(nums));
    }
}
